from math import sqrt

def dot(u, v):
	return sum(map(lambda(x, y): x * y, zip(u, v)))
	
def perp(u):
	return (-u[1], u[0], 0.0)
	
def mag(u):
	return sqrt(dot(u, u))

def scale(u, k):
	return map(lambda x: x * k, u)
	
def norm(u):
	return scale(u, mag(u))
	
def dist(u, v):
	return mag(map(lambda(x, y): x - y, zip(u,v)))
	
def sqrdist(u, v):
	u_v = map(lambda(x,y): x - y, zip(u,v))
	return u_v[0]*u_v[0] + u_v[1]*u_v[1] + u_v[2]*u_v[2]

def sumsqrs(u):
	return u[0]*u[0]+u[1]*u[1]+u[2]*u[2]